﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.Service.Day
{
    /// <summary>
    /// 持仓时间和收益率
    /// </summary>
    public class ServiceYieldInHoldTime : Benefit.Interface.Day.IYieldInHoldTime
    {
        Benefit.DB.DBManager db = null;
        public ServiceYieldInHoldTime(Benefit.DB.DBManager db)
        {
            this.db = db;
        }


        /// <summary>
        /// 删除持仓时间收益情况
        /// </summary>
        /// <param name="tradeHistoryId"></param>
        public void DeleteYieldHoldTime(int tradeHistoryId)
        {
            var query = db.YieldInHoldTime.Where(a => a.TradeHistoryId == tradeHistoryId);
            foreach (Models.Day.YieldInHoldTime t in query)
            {
                db.YieldInHoldTime.Remove(t);
            }
            db.SaveChanges();
        }
        /// <summary>
        /// 获取一个账号的持仓收益率情况
        /// </summary>
        /// <param name="tradeHistoryId"></param>
        /// <param name="accountid"></param>
        /// <returns></returns>
        public List<Models.Day.YieldInHoldTime> GetYieldInHoldTime(int tradeHistoryId, int accountid)
        {
            List<Models.Day.YieldInHoldTime> times = new List<Models.Day.YieldInHoldTime>();
            var query = db.YieldInHoldTime.Where(a => a.TradeHistoryId == tradeHistoryId).Where(a => a.AccountId == accountid);
            foreach (Models.Day.YieldInHoldTime t in query)
            {
                times.Add(t);
            }
            return times;
        }
    }
}
